<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    //  [1, 8, 3, 2, 9, 5, 4, 7]

    function f(arr) {
        for(let i=0;i<arr.length;i++){
            for(let j=i+1;j<arr.length;j++){
                if(arr[i] > arr[j]){
                    let tmp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = tmp;
                }
            }
        }
        return arr
    }
    let arr = [1, 8, 3, 2, 9, 5, 4, 7];
    let res = f(arr);

    document.write(res)


</script>
</body>
</html>